<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=1.0, initial-scale=1.0" />
    <title>1</title>
    <style>
      body {
        text-align: center;
        font-size: 16px;
      }
      .a {
        margin-bottom: 15px;
      }
    </style>
  </head>
  <body>
    <div class="a" id="a"></div>
  </body>
  <script src="http://e-static.oss-cn-shanghai.aliyuncs.com/js/uuidv4.min.js"></script>
  <script>
    browerId();
    function browerId() {
      var iframe = document.createElement('iframe');
      iframe.src = 'http://page.fastfenxiang.cn/html/pages/bid.html';
      iframe.style.display = 'none';
      iframe.frameBorder = 0;
      iframe.onload = function () {
        var w = this.contentWindow;
        var uid = uuidv4();

        w.postMessage('init', 'http://page.fastfenxiang.cn');

        window.onmessage = function (e) {
          if (e.data == 'undefined' || !e.data) {
            console.log('init iframe no have id-->', uid);
            document.querySelector('#a').innerHTML = uid;
          } else {
            console.log('init-->', e.data);
            document.querySelector('#a').innerHTML = e.data;
          }

          if (e.data == 'undefined' || !e.data) {
            w.postMessage(uid, 'http://page.fastfenxiang.cn');
          }
        };
      };

      document.body.appendChild(iframe);
    }
  </script>
</html>
